package bancoperu.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import bancoperu.model.Account;
import bancoperu.model.Customer;

public class StatementDAO extends BaseDAO {

	
	

	public Collection<Account> GetStatement(String AccountID) throws Exception {
		String query = "SELECT AccountBalance, CustomerID, AccountType FROM account WHERE AccountID=?";
		Collection<Account> lista = new ArrayList<Account>();
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
				
	
		try {
			
			con = ConexionBD.obtenerConexion();
			stmt = con.prepareStatement(query);
			stmt.setString(1, AccountID);
				
			
			rs = stmt.executeQuery();
			
			while (rs.next()) {			
				Account vo = new Account();
				

				stmt.setString(1, AccountID);
				
				vo.setAccountBalance(rs.getDouble("AccountBalance"));
				
				Customer cus = new Customer();
				cus.setCustomerId(rs.getString("CustomerID"));
				
				vo.setCustomer(cus);
				vo.setAccountType(rs.getInt("AccountType"));
				
				
				lista.add(vo);
				
			}
			
						
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new Exception(e.getMessage());
		} finally {
			
			this.cerrarResultSet(rs);
			this.cerrarConexion(con);
			this.cerrarStatement(stmt);
			
		}
			return lista;
		}}



